package com.lineage.data.npc.event;

import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Skills;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_CastleBuffSet extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_CastleBuffSet.class);
  
  private static final int[] allBuffSkill = new int[] { 26, 42, 48 };
  
  public static NpcExecutor get() {
    return new Npc_CastleBuffSet();
  }
  
  public int type() {
    return 1;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (pc.getInventory().consumeItem(40308, 1000L)) {
        int i = 0;
        while (i < allBuffSkill.length) {
          L1Skills skill = SkillsTable.get().getTemplate(allBuffSkill[i]);
          L1SkillUse skillUse = new L1SkillUse();
          skillUse.handleCommands(pc, allBuffSkill[i], pc.getId(), pc.getX(), pc.getY(), 
              skill.getBuffDuration(), 4);
          i++;
        } 
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_done"));
      } else {
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_adena"));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
